<%@page import="org.apache.jasper.tagplugins.jstl.core.ForEach"%>
<%@page import="kickboxing.model.Newsy"%>
<%@page import="java.util.List"%>
<%@page import="java.util.Iterator"%>
<%@page import="kickboxing.controller.NewsyManager"%>
<%@page import="kickboxing.model.Uzytkownik"%>


<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<!--  
	<a href="dodajNews.jsp">Dodaj nowy news</a><br>
	<a href="dodajZdjecie.jsp">Dodaj swoje zdjecie profilowe</a><br>
	<a href="userPokazZdjecieProfilowe.jsp">Pokaz swoje zdjecie profilowe</a><br>
--><p style=margin-top:-10px;></p>
		<% 
			
		
		 if( request.getParameter("id") == null || request.getParameter("id") == ""){
		
		
			String message = (String)request.getAttribute("message"); 
			if(message != null){
				
				out.println(message);
			}
			
			NewsyManager man = new NewsyManager();
			List <Newsy> listaPRO =  man.wysietlWszystkieNewsy();
			
			int perPage = 4;
			int size = listaPRO.size()-1;
			int pages;
			int start=0;
			
			
			
			
		    if( request.getParameter("pages") != null && request.getParameter("pages") != "")
		    {
		    	pages = (Integer.parseInt(request.getParameter("pages")));
		    	start = (pages - 1) * perPage;
		    	
		    	if(pages < 1)  pages = 1; 
		    	
		    }
		    else
		    {
		    	pages=1;
		    }
		    
		    int prev = pages - 1;
			int next = pages + 1;
		    
		    //out.println("pages: "+pages+"<br>start: "+start+"<br>size: "+size);
		    
		    for(int i = start; i<start+perPage; i++){
		    	
		    	
		    	if(i>size) break;
		    	
		    	
		    	else{ 
		    		%><div id=newsy_txt style="margin: 5px 5px 5px 5px;">
		    		<div align=left style="color: #954930; text-shadow: black 0.1em 0.1em 0.2em;"><b> <font face=Verdana size=1>
		    			<%= listaPRO.get(i).getTemat() %>
		    			</font></b>
		    			
		    		</div><div align=right><font face=Verdana size=1 color=#954930>
		    			<%= listaPRO.get(i).getData() %>	
		    		</font></div>
		    		<div align=justify style="margin-top:-5px;"><font face=Verdana size=1 color=white>
			    		<%
			    			int end = 250;
			    			if( listaPRO.get(i).getTresc().length() < end )
			    			{
			    		%>
			    		<% String removeHTML = NewsyManager.removeHTML(listaPRO.get(i).getTresc().trim()); %>
			    		<%= removeHTML+"</font></b></a></span>" %>
			    		<%	
			    			}else
			    			{
			    		%>
			    		<% String removeHTML = NewsyManager.removeHTML(listaPRO.get(i).getTresc().trim().substring(0, end)); %>
			    		<%= removeHTML+"</b></a></span>" %>
			    		
			    		<%	
			    			}
			    			
			    		%>... <a href="index.jsp?id=<%= listaPRO.get(i).getId_newsu() %>&kwiateknapisal=<%= listaPRO.get(i).getTemat() %>">
					<img src=img/mini/wiecej_png.png alt="wiecej">
					</a>	
		    		</font>
		    		
		    		</div><hr>
		    		</div>
		    		<%
		    		
		    }}
		   
		    
//konkretny NEWS

		    }else if(!request.getParameter("id").isEmpty()){
			
		    	response.sendError(404,"Gladiator: blad newsow");
			 	
			 }
			%>
			

